package optimization;

import optimization.LinearAlgebra;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class TabuList {

	Queue<double[]> list;
	int len;
	double rad;
	
	public TabuList() {
		this(8, 0.0001);
	}
	
	public TabuList(int length, double radius) {
		list = new LinkedList<double[]>();
		len = length;
		rad = radius;
	}

	public boolean equals(double[] a, double[] b, double radius)
	{
		return LinearAlgebra.vNorm2(LinearAlgebra.vSub(a, b)) < radius;
	}
		
	public boolean accept(double[] point) {
		/*
		System.out.print("TABU TRY " + LinearAlgebra.vPrint(point) + ", LIST : " );
		for (double[] d : list) { System.out.print(LinearAlgebra.vPrint(d)+ ", "); }
		System.out.println();
			*/
		
		// check if point in list
		for (double[] p : list) {
		//	System.out.print(LinearAlgebra.vPrint(p) + ", ");
			if (equals(p, point, rad)) {
		//		System.out.println("TABU BLOCK " + LinearAlgebra.vPrint(point) + ", EQ");
				return false;
			}
		}
		// not, so accept & add to list
		if (list.size() >= len) { list.remove(); }
		list.add(point.clone());
		return true;
	}
}
